﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Validate
{
    public class GreaterThanValidatorAttribute : ValidatorAttribute
    {
        public IComparable LowerBound { get; set; }

        public GreaterThanValidatorAttribute(string messageTemplate, int lowerBound)
            : base(messageTemplate)
        {
            this.LowerBound = lowerBound;
        }

        public GreaterThanValidatorAttribute(string messageTemplate, double lowerBound)
            : base(messageTemplate)
        {
            this.LowerBound = lowerBound;
        }

        public GreaterThanValidatorAttribute(string messageTemplate, DateTime lowerBound)
            : base(messageTemplate)
        {
            this.LowerBound = lowerBound;
        }

        public GreaterThanValidatorAttribute(string messageTemplate, string thenTime, double addDays)
            : base(messageTemplate)
        {
            if (thenTime == null || thenTime == GetBaseTime)
                this.LowerBound = DateTime.Now.AddDays(addDays);
            else
                this.LowerBound = DateTime.Parse(thenTime).AddDays(addDays);
        }

        public override Validator CreateValidator()
        {
            return new GreaterThanValidator(this.MessageTemplate, this.LowerBound);
        }

        public const string GetBaseTime = "1900-01-01";

    }
}
